<meta charset="UTF-8">

<h1>登录页</h1>
<form action="">
    <p>账号<input type="text"></p>
    <p>密码<input type="password"></p>

    <p>验证码<input type="text">
    <img src="http://kg.zhaodashen.cn/v1/public/captcha.jsp" alt="验证码图">
    </p>
    <p>记住密码<input type="checkbox"></p>
    <p><input type="submit"value='登录'></p>
</form>

<script src="./axios.js"></script>
<script>
    let submitBtn=document.querySelector('input[type=submit]')
    submitBtn.onclick=async function(evt){
        let e=evt || window.event
        e.preventDefault()
        let uname=document.querySelectorAll('input')[0].value
        let pwd=document.querySelectorAll('input')[1].value
        let captcha=document.querySelectorAll('input')[2].value
        console.log(uname,pwd,captcha)
        let res=await post('http://kg.zhaodashen.cn/v1/public/login.jsp',{uname,pwd,captcha},'json')
        // console.log(res)
        if (res.meta.state===200){
            alert(res.meta.msg)
            let state=document.querySelector('input[type=checkbox]').checked
            if(state){
                localStorage.setItem('uname',res.data.uname)
                localStorage.setItem('expires',(new Date).getTime()+1000*60*60*24*7)
            } else {
                sessionStorage.setItem('uname',res.data.unmae)
            }
            location.href='./member.html'
        } else {
            alert(res.meta.msg)
        }
    }

</script>